home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / mutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-16  |  5.8 KB  |  217 lines

  1. /*    MUTILS.C
  2.  *
  3.  * Miscellaneous utility functions for MIDAS Sound System used
  4.  * by various system components.
  5.  *
  6.  * $Id: mutils.c,v 1.3 1997/01/16 18:41:59 pekangas Exp $
  7.  *
  8.  * Copyright 1996,1997 Housemarque Inc.
  9.  *
  10.  * This file is part of the MIDAS Sound System, and may only be
  11.  * used, modified and distributed under the terms of the MIDAS
  12.  * Sound System license, LICENSE.TXT. By continuing to use,
  13.  * modify or distribute this file you indicate that you have
  14.  * read the license and understand and accept it fully.
  15. */
  16.  
  17.  
  18. #include "lang.h"
  19. #include "mutils.h"
  20. #include "string.h"
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23.  
  24. /****************************************************************************\
  25. *
  26. * Function:     int mGetKey(void)
  27. *
  28. * Description:  Waits for a keypress and returns the read key
  29. *
  30. * Returns:      ASCII code for the key pressed. Extended keycodes are
  31. *               returned with bit 8 set, eg. up arrow becomes \x148.
  32. *
  33. \****************************************************************************/
  34.  
  35. int CALLING mGetKey(void)
  36. {
  37.     char c;
  38. #ifdef __LINUX__
  39. #define getch getchar
  40. #endif
  41.     
  42.     c = getch();
  43.     
  44.     if ( !c )
  45.     return 0x100+getch();
  46.     else
  47.     return c;
  48. };
  49.  
  50. /****************************************************************************\
  51. *
  52. * Function:     int mStrLength(const char *str)
  53. *
  54. * Description:  Calculates the length of a ASCIIZ string
  55. *
  56. * Input:        char *str               pointer to string
  57. *
  58. * Returns:      String length excluding the terminating '\0'.
  59. *
  60. \****************************************************************************/
  61.  
  62. int CALLING mStrLength(const char *str)
  63. {
  64.     return strlen(str);
  65. }
  66.  
  67. /****************************************************************************\
  68. *
  69. * Function:     void mStrCopy(char *dest, const char *src);
  70. *
  71. * Description:  Copies an ASCIIZ string from *src to *dest.
  72. *
  73. * Input:        char *dest              pointer to destination string
  74. *               char *src               pointer to source string
  75. *
  76. \****************************************************************************/
  77.  
  78. void CALLING mStrCopy(char *dest, const char *src)
  79. {
  80.     strcpy(dest, src);
  81. }
  82.  
  83. /****************************************************************************\
  84. *
  85. * Function:     void mStrAppend(char *dest, const char *src);
  86. *
  87. * Description:  Appends an ASCIIZ string to the end of another.
  88. *
  89. * Input:        char *dest              pointer to destination string
  90. *               char *src               pointer to source string
  91. *
  92. \****************************************************************************/
  93.  
  94. void CALLING mStrAppend(char *dest, const char *src)
  95. {
  96.     strcat(dest, src);
  97. }
  98.  
  99. /****************************************************************************\
  100. *
  101. * Function:     void mMemCopy(void *dest, const void *src, unsigned numBytes);
  102. *
  103. * Description:  Copies a memory block from *src to *dest.
  104. *
  105. * Input:        void *dest              pointer to destination
  106. *               void *src               pointer to source
  107. *               unsigned numBytes       number of bytes to copy
  108. *
  109. \****************************************************************************/
  110.  
  111. void CALLING mMemCopy(void *dest, const void *src, unsigned numBytes)
  112. {
  113.     memcpy(dest, src, numBytes);
  114. }
  115.  
  116.  
  117. /****************************************************************************\
  118. *
  119. * Function:     int mMemEqual(const void *m1, const void *m2,
  120. *                   unsigned numBytes);
  121. *
  122. * Description:  Compares two memory blocks.
  123. *
  124. * Input:        void *m1                pointer to memory block #1
  125. *               void *m2                pointer to memory block #2
  126. *               unsigned numBytes       number of bytes to compare
  127. *
  128. * Returns:      1 if the memory blocks are equal, 0 if not.
  129. *
  130. \****************************************************************************/
  131.  
  132. int CALLING mMemEqual(const void *m1, const void *m2, unsigned numBytes)
  133. {
  134.     if ( memcmp(m1, m2, numBytes ) )
  135.       return 0;
  136.     else
  137.       return 1;
  138. }
  139.  
  140. /****************************************************************************\
  141. *
  142. * Function:     long mHex2Long(const char *hex)
  143. *
  144. * Description:  Converts a hexadecimal string to a long integer.
  145. *
  146. * Input:        char *hex               pointer to hex string, ASCIIZ
  147. *
  148. * Returns:      Value of the string or -1 if conversion failure.
  149. *
  150. \****************************************************************************/
  151.  
  152. long CALLING mHex2Long(const char *hex)
  153. {
  154.     static unsigned int l;
  155.  
  156.     if ((sscanf(hex, "%x", &l) ) > 0 )
  157.         return l;
  158.     else
  159.         return -1;
  160. }
  161.  
  162.  
  163. /****************************************************************************\
  164. *
  165. * Function:     long mDec2Long(const char *dec)
  166. *
  167. * Description:  Converts an unsigned decimal string to a long integer
  168. *
  169. * Input:        char *dec               pointer to string, ASCIIZ
  170. *
  171. * Returns:      Value of the string or -1 if conversion failure.
  172. *
  173. \****************************************************************************/
  174.  
  175. long CALLING mDec2Long(const char *dec)
  176. {
  177.     static int l;
  178.  
  179.     if ( (sscanf(dec, "%d", &l)) > 0 )
  180.         return l;
  181.     else
  182.         return -1;
  183. }
  184.  
  185.  
  186. /***************************************************************************\
  187. *
  188. * Function:     char *mGetEnv(const char *envVar);
  189. *
  190. * Description:  Searches a string from the environment
  191. *
  192. * Input:        envVar                  environment variable name, ASCIIZ
  193. *
  194. * Returns:      Pointer to environment string value (ASCIIZ), NULL if string
  195. *               was not found.
  196. *
  197. \***************************************************************************/
  198.  
  199. char * CALLING mGetEnv(const char *envVar)
  200. {
  201.     return getenv(envVar);
  202. }
  203.  
  204. /*
  205.  * $Log: mutils.c,v $
  206.  * Revision 1.3  1997/01/16 18:41:59  pekangas
  207.  * Changed copyright messages to Housemarque
  208.  *
  209.  * Revision 1.2  1996/05/24 20:40:12  jpaana
  210.  * Fixed mMemEqual
  211.  *
  212.  * Revision 1.1  1996/05/24 16:20:36  jpaana
  213.  * Initial revision
  214.  *
  215.  *
  216. */
  217.